import { FC, useState, useEffect } from 'react';
import Child from './components/Child';

const Ts: FC = () => {
  // useState没有给类型，会做自动地类型推断，推断出count是数字类型
  // <number>表示泛型
  const [count, set_count] = useState<number>(4);

  // void表示没有返回值
  const fn2 = (): void => {
    set_count((v) => v + 1);
  };

  useEffect(() => {
    fn2();
  }, []);

  return (
    <>
      <div>这是ts组件</div>
      <button>-</button>
      <span>{count}</span>
      <button onClick={fn2}>+</button>
      <Child count={count} />
    </>
  );
};

export default Ts;
